package com.hxd.otc.other.rong;

import android.net.Uri;
import android.support.annotation.NonNull;

import com.hxd.otc.module.my.bean.RongUserInfoBean;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.LogUtils;

import io.rong.imkit.RongIM;
import io.rong.imlib.model.UserInfo;

/**
 * Created by lzy on 2018/8/15 0015.
 * description ${融云用户信息提供者}
 */
public class RongUserInfoProvider implements RongIM.UserInfoProvider {

    private UserModel mUserModel = UserModel.getInstance();

    @Override
    public UserInfo getUserInfo(final String userId) {
        mUserModel.getUserInfoById(userId, new BaseObserver<RongUserInfoBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull RongUserInfoBean rongUserInfoBean) {
                LogUtils.d("从服务器获取融云用户：" + rongUserInfoBean);
                RongIM.getInstance().refreshUserInfoCache(new UserInfo(rongUserInfoBean.getUserId(), rongUserInfoBean.getNickName(), Uri.parse("")));
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                LogUtils.e("从服务器获取融云用户（" + userId + "）失败：" + errMessage);
            }
        }, null);
        return null;
    }
}